package com.zyasdk.deng;

import java.io.File;
import java.security.MessageDigest;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;


public class MdUtils {

	 private static MessageDigest md5 = null;
	    static {
	        try {
	            md5 = MessageDigest.getInstance("MD5");
	        } catch (Exception e) {
	            System.out.println(e.getMessage());
	        }
	    }

	    /**
	     * 用于获取一个String的md5值
	     * @param string
	     * @return
	     */
	    public static String getMd5(String str) {
	        byte[] bs = md5.digest(str.getBytes());
	        StringBuilder sb = new StringBuilder(40);
	        for(byte x:bs) {
	            if((x & 0xff)>>4 == 0) {
	                sb.append("0").append(Integer.toHexString(x & 0xff));
	            } else {
	                sb.append(Integer.toHexString(x & 0xff));
	            }
	        }
	        return sb.toString();
	    }
	    
	    /**
		 * 安装apk
		 * 
		 * @param url
		 */
		public static void installApk(String saveFileName,Context context) {
			File apkfile = new File(saveFileName);
		
			if (!apkfile.exists()) {
				return;
			}
			Intent i = new Intent(Intent.ACTION_VIEW);
			i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
			i.setDataAndType(Uri.parse("file://" + apkfile.toString()), "application/vnd.android.package-archive");
			context.startActivity(i);
		//	callback.OnBackResult("finish");

		}
}
